<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3" xmlns:head="http://www.w3.org/1999/html">
<head th:include="public/public_css::public_css ('库位组管理')" />

<body style="background-color: #f2f2f2;">
<div class="layui-fluid larry-wrapper">
    <div class="layui-card">
        <div class="layui-row layui-col-space30" style=" margin-left: 10px;">
            <div class="layui-col-xs24">
                    <legend>库位组信息</legend>
                    <input type="hidden" name="ckmc">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">库位组名称</label>
                            <div class="layui-input-block">
                                <input type="text" name="mc" id="mc" placeholder="库位组名称" lay-verify="required" autocomplete="off" class="layui-input "/>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">当前仓库</label>
                            <div class="layui-input-block">
                                <input  th:value="${ckmc}" id="ckmc" autocomplete="off" class="layui-input" readonly/>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">库位组描述</label>
                        <div class="layui-input-block">
                            <input type="text" name="ms" id="ms" placeholder="库位组描述"  autocomplete="off" class="layui-input "/>
                        </div>
                    </div>
                        <div><input type="hidden" name="sfyx" id="sfyx" value="1" readonly></div>
                    </div>
                <form class="layui-form layui-card-header  layui-card-header-auto" id="searchForm">
                    <legend>库位信息</legend>
                    <div class="layui-inline">
                        <label class="layui-form-label">库位组类型</label>
                        <select name="kwzlx" lay-filter="filter" id="kwzlx">
                            <option value="0">收货</option>
                            <option value="1">上架</option>
                            <option value="2">集货</option>
                            <option value="3">作业区</option>
                        </select>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">库位名称</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="mc1" name="mc" placeholder="库位名称"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">库位层数</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="cs" name="cs" placeholder="库位层数"/>
                        </div>
                    </div>
                    <div class="layui-inline inline-search-btn">
                        <a class="layui-btn layui-btn-normal" data-type="reload" id="search_button"> 查询 </a>
                    </div>
                    <div class="layui-inline inline-reset-btn">
                        <button type="reset" class="layui-btn layui-btn-primary" style="background-color: #1e9fff; color: white;" >重置</button>
                    </div>
                </form>
                <!--列表-->
                <section class="panel panel-padding layui-card-body" id="tablediv" >
                    <div class="pro">
                        <table id="table"></table>
                    </div>
                </section>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" jq-filter="submit" lay-submit="" lay-filter="addKwz">立即提交</button>
                        <button type="button"  onclick="cz()" class="layui-btn layui-btn-primary">重置</button>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>
</body>


<div th:include="public/public_js::public_js"></div>
<style type="text/css">
#tablediv{
    display: none;
}
</style>
<script>
    //	回车查询
    document.onkeydown = function(event) {
        e = event ? event : (window.event ? window.event : null);
        if (e.keyCode == 13) {
            //执行的方法
            $('#search_button').on('click', function () {
            });
        }
    };
    layui.use(['list','layer','zzpUtils','jquery','laydate'],function () {
        var zzpUtils= layui.zzpUtils,
            $ = layui.jquery,
            laydate = layui.laydate;
        var form = layui.form;
        window.operateEvent ={
            "click .layui-btn-primary":function (e, value, row, index) {
               // alert(row.mc);
            },
            "click #delRow": function (e, value, row, index) {//行按钮删除  btn_stop
                del_(index);
            },
        }
        var ids=[];
        var $table = zzpUtils.table({
            elem: '#table',
            isApi: true,
            pagination:true,
            url: '/wmslibrarypositiongroup/listkw',
            columns: [{
                field: '',
                checkbox: true,
                // 显示复选框
                formatter: function (i,row) {
                    // 每次加载 checkbox 时判断当前 row 的 id 是否已经存在全局 Set() 里
                    if ($.inArray(row.id, ids) != -1) {// 因为 判断数组里有没有这个 id
                        return {
                            checked: true               // 存在则选中
                        }
                    }

                }
            }, {
                field: 'mc',
                title: '库位名称'
            },{
                field: 'show_lx',
                title: '库位类型'
            },{
                field: 'cs',
                title: '库位层数'
            }],
            queryParams: function () {//查询条件
                return  zzpUtils.getFormJson($("#searchForm"));
            },
            detailFormatter: function (index, row) {
                return "这里就没有确定过11";
            },
            onCheck: function (row) {
                btn_cha(row.id,1);
            },
            onUncheck: function (row) {
                btn_cha(row.id,1);
            },
            onCheckAll: function (rows) {
                $.each(rows, function (i, item) {
                    btn_cha(item.id,2);
                });

            },
            onUncheckAll: function (rows) {
                $.each(rows, function (i, item) {
                    btn_cha(item.id,3);
                });
            }
        });
        /*function btn_cha(id){
            if(ids.indexOf(id)>-1){
                var index = ids.indexOf(id);
                if (index > -1) {
                    ids.splice(index, 1);
                }
            }else{
                ids.push(id);
            }
        }*/
        //it 1 反选/勾选 ；2 全选；3全反选
        function btn_cha(id,it) {
            if (it == 1) {

                if (ids.indexOf(id) > -1) {
                    var index = ids.indexOf(id);
                    if (index > -1) {
                        ids.splice(index, 1);
                    }
                } else {
                    ids.push(id);
                }
            } else if (it == 3) {
                if (ids.indexOf(id) > -1) {
                    var index = ids.indexOf(id);
                    if (index > -1) {
                        ids.splice(index, 1);
                    }
                }
                /* else {
                 ids.push(id);
                 }*/

            } else{
                if (ids.indexOf(id) > -1) {
                    var index = ids.indexOf(id);
                    if (index > -1) {
                        /*ids.splice(index, 1);*/
                    }
                }else {
                    ids.push(id);
                }
            }
        }
        $('#search_button').on('click', function () {
            if ($('#kwzlx').val() !== '') {
                $('#tablediv').css('display', 'block');
            } else {
                layer.msg('请选择库位组类型', {icon: 5,shift: 6});
            }
        })
        $(".inline-search-btn").on('click',function () {
            zzpUtils.refreshTable("#table");
        })

        form.on("submit(addKwz)",function(data){
            var list =[];

            var selectData= $('#table').bootstrapTable('getSelections');
            var idss=[];
            $.each(ids, function (i, item) {
                list.push({
                    "id":item
                });
            });
            var data = {
                "kwzlx":$('#kwzlx').val(),
                "mc":$('#mc').val(),
                "ms":$('#ms').val(),
                "sfyx":$('#sfyx').val(),
                "list":list
            };
            if($('#mc').val()==''){
                layer.msg("库位组名称是必填项", {icon: 5,shift: 6});
            }else{
                if(list.length>0) {
                    zzpUtils.confirm("是否确定添加", function (index) {
                        zzpUtils.action({
                            url: "/wmslibrarypositiongroup/add",
                            data: JSON.stringify(data),
                            success: function (data) {
                                if (data.type == 'success') {
                                    top.layer.msg(data.title);
                                    setTimeout(function () {
                                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                        parent.layer.close(index); //再执行关闭

                                    //top.layer.msg(data.title);
                                    }, 500);
                                }else{
                                    layer.confirm(data.message,{btn: ['确定'],title:data.title});
                                }
                            }, error: function (xhr, textStatus) {
                                console.log(textStatus);
                                console.log(xhr);
                            }
                        })
                    })
                }else{
                    layer.msg("请选择库位", {icon: 5,shift: 6});
                }
            }
            return false;
        });
    });
    function cz() {
        $('#mc').val("");
        $('#ms').val("");
    }
</script>
</html>